var uid,cur_page=1;
var cur_statu = 0;
var is_first = true;
var nomore = false;
var res = [];
var app = angular.module('app',[]);
app.controller('my_controller',function($scope,$http){
	$scope.intview = function(){
		if(nomore){return;}
		plus.nativeUI.showWaiting('加载中...');
		$http({
			method:'post',
			url:apiRoot,
			data:{
				action:'User.getOrderInfo',
				uid:uid,					
				state:cur_statu, 
				type:type,
				page:cur_page
			}
		}).then(function success(result){
			plus.nativeUI.closeWaiting();
			if(typeof(result.data.data) != 'object'){
				if(cur_page == 1){ 
					$scope.res = [];
				}
				$scope.kkk = 1;
				nomore = true; 
				return; 
			}
			res.push(result.data.data);
			$scope.res = res;
			cur_page++;
		},function errorFunction(e){
			plus.nativeUI.closeWaiting(); 
			plus.closeWaiting();
			console.log(JSON.stringify(e));
		})
	}
	
	//传ddid给 填写物流单页面 "input_logistics_info.html"
	$scope.send_ddid = function($id){
		plus.webview.create('input_logistics_info.html', 'input_logistics_info.html',{},{order_id:$id}).show('pop-in');
	}
	
	//查看物流信息  
	$scope.query_logistics_info = function(name,num){
		console.log(name+"######"+num);
		plus.webview.create('logistics.html', 'logistics.html',{},{company_name:name,order_num:num}).show('pop-in');
	}
	
	//打开订单详情页
	$scope.open_detail = function(id,status){
		plus.webview.create('fh_order_detail.html', 'fh_order_detail.html',{},{order_id:id,type_status:status}).show('pop-in');
	}
	
	//申请提现
	$scope.withdrawals = function($id,$state){
		plus.nativeUI.showWaiting('提交申请中...');
		$http({
			method:'post',
			url:apiRoot,
			data:{
				action:'Orderid.orderidstate',
				id:$id,					
				state:$state, 
			}
		}).then(function success(result){
			plus.nativeUI.closeWaiting();
			mui.toast('提交成功');
			$scope.is_return = result.data.data;
			console.log(JSON.stringify($scope.is_return));
		},function errorFunction(e){
			plus.nativeUI.closeWaiting();
			console.log(JSON.stringify(e));
		})
	}

})
var type;
document.addEventListener('plusready',function(){
	ws = plus.webview.currentWebview();
	uid = plus.storage.getItem('uid');
	type = ws.type;
	appElement = document.querySelector('[ng-controller=my_controller]');
	$scope = angular.element(appElement).scope();
	$scope.intview();
	$('.mui-segmented-control .mui-control-item').on('tap',function(){		
		$('#sliderProgressBar').animate({'left':($(this).index()*$('.mui-segmented-control.mui-segmented-control-inverted .mui-control-item').innerWidth()) + 'px'},'fast');
		$('.mui-control-content').eq($(this).index()).addClass('mui-active').siblings().removeClass('mui-active');
		res = [];
		$scope.not_more = 0;
		nomore = false;
		cur_page = 1;
		cur_statu = $(this).index();
		console.log(cur_statu);
		$scope.intview();
	})	
})

